package com.fp.m7.server.util;

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

/**
 * Server-side utils with "heavy" stuff.
 * 
 * @author 7
 */
public class ImageUtils {

    public static BufferedImage resizeImage(BufferedImage image, int newWidth, int newHeight) {
        // Create new (blank) image of required (scaled) size
        BufferedImage scaledImage = new BufferedImage(newWidth, newHeight, image.getType());

        // Paint scaled version of image to new image
        Graphics2D graphics2D = scaledImage.createGraphics();
        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2D.drawImage(image, 0, 0, newWidth, newHeight, null);

        // clean up
        graphics2D.dispose();

        return scaledImage;
    }
}
